package com.ihomey.linkuphome.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ihomey.linkuphome.R;
import com.ihomey.linkuphome.base.SimpleBaseAdapter;
import com.ihomey.linkuphome.entities.Category;

import java.util.List;

public class AddedCategoryAdapter extends SimpleBaseAdapter<Category> {

    public AddedCategoryAdapter(Context context, List<Category> data) {
        super(context, data);
    }

    @Override
    public int getItemResource() {
        return R.layout.item_lamp_added;
    }

    @Override
    public View getItemView(int position, View convertView, ViewHolder holder) {
        TextView name = holder.getView(R.id.tv_lamp_categoryName);
        TextView type = holder.getView(R.id.tv_lamp_categoryType);
        ImageView icon = holder.getView(R.id.iv_lamp_categoryIcon);
        Category category = (Category) getItem(position);

        if (category.getType() == 1) {
            convertView.setBackgroundResource(R.drawable.item_lamp_lawn_selector);
            type.setText("C3");
            name.setText(R.string.device_type_lawn);
            icon.setImageResource(R.drawable.lamp_lawn);
        } else if (category.getType() == 2) {
            convertView.setBackgroundResource(R.drawable.item_lamp_unadded_selector);
            type.setText("R2");
            name.setText(R.string.device_type_lawn_rgb);
            icon.setImageResource(R.drawable.lamp_rgb);
        }

        return convertView;
    }


    public void add(int i, Category category) {
        data.add(i, category);
        notifyDataSetChanged();
    }
}